package com.controller;

import com.service.RefreshService;
import com.util.GetBeanInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.common.Mapper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping
public class BeanController {

    @Autowired
    private ApplicationContext applicationContext;

    @Autowired
    RefreshService refreshService;
    @GetMapping("/beanList")
    public List<String> beanList() {
        return Arrays.asList(applicationContext.getBeanDefinitionNames());
    }

    /**
    * @Description 实时刷新  例如刷新yyb_city表,那beanName就传yybCity
    * @Author fangjunjie 
    * @Date 2021/5/19 17:25
    */
    @GetMapping("/refreshNow")
    public String refreshNow(String beanName) throws Exception {
        List<String> beanNames=new ArrayList<>();
        beanNames.add(beanName);
        refreshService.synBYBeanNames(beanNames);
        return "refresh now success!";
    }
}